package com.nondo.dean.platform.tool;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import com.nondo.dean.common.tool.DateUtils;
import com.nondo.dean.platform.domain.Coupon;

public class CouponUtils {
    
    /**
     * 优惠码长度
     */
    private static final int CODE_LENGTH = 10;
    
    /**
     * 优惠码长度
     */
    private static final String CODE_PREFIX = "YHM";
    
    public static String getFixLenthString() {
        Random rm = new Random();
        // 获得随机数
        double pross = (1 + rm.nextDouble()) * Math.pow(10, CODE_LENGTH);
        // 将获得的获得随机数转化为字符串
        String fixLenthString = String.valueOf(pross);
        // 返回固定的长度的随机数
        return fixLenthString.substring(2, CODE_LENGTH + 1);
    }
    
    /**
     * 优惠券规则
     * @return
     */
    public static List<Coupon> getCouponList() {
        List<Coupon> couponList = new ArrayList<Coupon>();
        Coupon coupon = new Coupon();
        coupon.setCode(CODE_PREFIX+getFixLenthString());
        Date nowDate = new Date();
        Date exprireTime = DateUtils.addDays(nowDate, 1);
        coupon.setExprireTime(exprireTime);
        BigDecimal reliefAmount = new BigDecimal(100.00);
        coupon.setReliefAmount(reliefAmount);
        BigDecimal useAmount = new BigDecimal(10000.00);
        coupon.setUseAmount(useAmount);
        coupon.setStatus(0);
        couponList.add(coupon);
        return couponList;
    }
}
